<template>
    <div class="content">
        <div class="clear">
            <Form inline class="fl">
                <DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
                </DatePicker>
                <Button class="m-r10" @click="chaxun(1)">今日</Button>
                <Button class="m-r10" @click="chaxun(2)">近7天</Button>
                <Button class="m-r10" @click="chaxun(3)">近30天</Button>
                <Button type="primary" @click="query">查询</Button>
            </Form>
        </div>
        <fieldset>
            <legend>汇总</legend>
            <div>
                <table>
                    <tbody>
                        <tr>
                          <td>累积分享奖励:
                            <span class="blue">{{ huizong.directAward == null ? 0 : huizong.directAward }}</span>
                          </td>
                          <td>累积分享奖励:
                            <span class="blue">{{ huizong.shareAward == null ? 0 : huizong.shareAward }}</span>
                          </td>
                          <td>累积签到奖励:
                            <span class="blue">{{ huizong.signAward == null ? 0 : huizong.signAward }}</span>
                          </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </fieldset>
        <Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
        <Table stripe :columns="columns1" :data="list" ref="table"></Table>
        <Page :total="dataCount" show-elevator :page-size="pageSize" show-total  @on-change="changepage"></Page>
    </div>
</template>
<script>
export default {
  data () {
    return {
      list:[],
      huizong: {},
      startTime: '',
      endTime: '',
      falg: false,
      // 分页
      ajaxHistoryData: [],
      // 初始化信息总条数
      dataCount: 0,
      // 每页显示多少条
      pageSize: 20,
      columns1: [
        {
          title: '日期',
          key: 'createTime',
          align: 'center',
          sortable: true,
          render: (h, params) => {
              return h('div', params.row.createTime.substring(0,10))
          }
        },
        {
          title: '累积分享奖励',
          align: 'center',
          key: 'directAward'
        },
        {
          title: '累积分享奖励',
          align: 'center',
          key: 'shareAward'
        },
        {
          title: '累积签到奖励',
          align: 'center',
          key: 'signAward'
        }
      ]
    }
  },
  methods: {
    exportData () {
      this.$refs.table.exportCsv({
        filename: 'EB奖励'
      })
    },
    // 处理时间段时间格式
    getTime (daterange) {
      this.dataValue = daterange
    },
    //获取数据
    getList () {
      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({

      })
      this.axios
        .post('financial/platformlist', params, {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          if (res.data.code == 8008) {
            // console.log(res)
            this.list = res.data.data.ebkcVOList
            this.dataCount = this.list.length
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({ name: 'login' })
          }
        })
    },
    // 获取全部汇总
    getHuizong () {
      let token = localStorage.getItem('mytoken')
      this.axios
        .get('financial/platform', {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res);
          if (res.data.code == 8008) {
            this.huizong = res.data.data.ebkcVO
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({ name: 'login' })
          }
        })
    },
    // 查询
    query () {
        let token = localStorage.getItem('mytoken')
        let params = this.qs.stringify({
          startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
          endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
        })
        this.axios
          .post('financial/platformlist', params, {
            headers: {
              Authorization: 'bearer ' + token
            }
          })
          .then(res => {
            if (res.data.code == 8008) {
            // console.log(res)
              this.list = res.data.data.ebkcVOList
              this.handleListApproveHistory()
            } else if (res.data.code == 4004) {
              this.$Message.info(res.data.message)
            } else if (res.data.code == 5501) {
              this.$Message.info(res.data.message)
              localStorage.removeItem('mytoken')
              this.$router.push({ name: 'login' })
            }
          })

    },
    // // 今日 7日 一个月 数据
    chaxun (id) {
      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        typeId: id
      })
      this.axios
        .post('financial/platformlist', params, {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res);
          if (res.data.code == 8008) {
            this.list = res.data.data.ebkcVOList
            this.handleListApproveHistory()
            this.$Message.info(res.data.message)
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({ name: 'login' })
          }
        })
    },
    // 分页
    handleListApproveHistory () {
      // 保存取到的所有数据
      this.ajaxHistoryData = this.list
      this.dataCount = this.list.length
      // 初始化显示，小于每页显示条数，全显，大于每页显示条数，取前每页条数显示
      if (this.dataCount < this.pageSize) {
        this.list = this.ajaxHistoryData
      } else {
        this.list = this.ajaxHistoryData.slice(0, this.pageSize)
      }
    },
    changepage (index) {
      var _start = (index - 1) * this.pageSize
      var _end = index * this.pageSize
      this.list = this.ajaxHistoryData.slice(_start, _end)
    },

  },
  created () {
    this.getList()
    this.getHuizong()
    setTimeout(() => {
      this.handleListApproveHistory()
    }, 500)
  },
  mounted () {
    this.$Message.config({
      top: 250
    })
  }
}
</script>
